home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
-
- DEMO 2
-
- Demonstrates the speed difference between compiled bitmap, conventional
- masked planar bitmap, and video bitmap blits.
-
- **************************************************************************/
-
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctype.h>
- #include <malloc.h>
- #include <dos.h>
- #include <time.h>
- #include "xlib.h"
- #include "xcbitmap.h"
- #include "xpbitmap.h"
- #include "xvbitmap.h"
- #include "xbmtools.h"
- #include "xtext.h"
- #include "xrect.h"
- #include "xrect.h"
-
- /* Macro to make pointer parameters model independent */
- //#define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
-
- char turtle[] = {
- 20,30,
- /* | . | . | . | . */
- 8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
- 0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
- 0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 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, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
-
-
- char *pbm, *vbm;
- char *newfnt;
-
- char *
- AllocatedSprite(int width, int height, int logical_width, char * bitmap)
- {
- char * result;
- int size;
-
- pbm = (char *)malloc(width * height + 2);
- x_bm_to_pbm(bitmap,pbm);
-
- result = (char *)malloc((width * height * 7) / 2 + 1025);
- if (result == 0)
- return(0);
- size = x_compile_bitmap(logical_width, bitmap, result);
-
- return (char *)realloc(result, size);
- }
-
-
-
- void load_user_fonts(){
- FILE *f;
- int i; char c;
- f=fopen("c:\\font.fnt","rb");
- f=fopen("smalthin.fnt","rb");
- newfnt = (char *)malloc( 676 );
- for (i=0;i< 676;i++){
- fread(&c,1,1,f);
- *(newfnt+i)=c;
- }
- fclose(f);
- x_text_init();
- x_register_userfont((BYTE *)newfnt);
- x_set_font(2);
- }
-
- void
- main()
- {
- int i,j,k;
-
- double ratio,ratio2;
- clock_t pbm_t0,pbm_t1,cbm_t0,cbm_t1,vbm_t0,vbm_t1;
- long vbm_ticks,pbm_ticks,cbm_ticks;
- char * TurtleSprite;
-
- x_set_mode(X_MODE_320x240,368);
-
- TurtleSprite = AllocatedSprite(20, 30, 92, turtle);
-
- // vbm = x_make_vbm(turtle,&NonVisual_Offs);
- // if (!vbm) {
- // sound(1000);
- // delay(100);
- // nosound();
- // }
-
- load_user_fonts();
- x_bgprintf(0,0,0,14,0,
- "This is a demo to show the speed difference between");
- x_bgprintf(0,8,0,14,0,
- "compiled, planar and video bitmaps. The bitmap:");
-
- x_put_cbitmap(140, 18, 0, TurtleSprite);
-
- x_bgprintf(0,48,0,14,0,
- "This demo uses the NON CLIPPED, MASKED versions of");
- x_bgprintf(0,56,0,14,0,
- " 'PBM' and VBM' put functions");
- x_bgprintf(0,78,0,14,0,
- "Press a key to start with PLANAR BITMAP demo");
-
- getch();
- x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
-
-
- pbm_t0 = clock();
- for (k=0;k<3;k++)
- for (j=0;j<(ScrnPhysicalHeight/30);j++)
- for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
- x_put_masked_pbm(i*20, j*30, 0, (BYTE *)pbm);
- pbm_t1 = clock();
- pbm_ticks = pbm_t1 - pbm_t0;
- /*
- x_bgprintf(0,0,0,14,0,
- "Press a key to start with the VIDEO BITMAP demo");
-
- getch();
- x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
-
-
- gettime(&vbm_t0);
- for (k=0;k<3;k++)
- for (j=0;j<(ScrnPhysicalHeight/30);j++)
- for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
- x_put_masked_vbm(i*20, j*30, 0, vbm);
- gettime(&vbm_t1);
- vbm_ticks = (((long)vbm_t1.ti_hund
- +((long)vbm_t1.ti_sec*100)
- +((long)vbm_t1.ti_min*6000)) -
- (((long)vbm_t0.ti_hund
- +((long)vbm_t0.ti_sec*100)
- +((long)vbm_t0.ti_min*6000))));
-
- */
-
-
- x_bgprintf(0,0,0,14,0,
- "Now Press a key to start with COMPILED BITMAP demo");
-
- getch();
- x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
-
- cbm_t0 = clock();
- for (k=0;k<3;k++)
- for (j=0;j<(ScrnPhysicalHeight/30);j++)
- for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
- x_put_cbitmap(i*20, j*30, 0, TurtleSprite);
- cbm_t1 = clock();
- cbm_ticks = cbm_t1 - cbm_t0;
- if (cbm_ticks==0){
- cbm_ticks=1;
- pbm_ticks+=1;
- vbm_ticks+=1;
- }
- ratio = pbm_ticks*(double)1.0/cbm_ticks;
- // ratio2 = vbm_ticks*(double)1.0/cbm_ticks;
-
- x_set_font(1);
- x_bgprintf(0,ScrnPhysicalHeight-30,0,14,0,
- "s/100 PBM=%ld CBM=%ld - %4.1lf:1",
- pbm_ticks, cbm_ticks,ratio,ratio2);
- x_set_font(2);
- x_bgprintf(0,ScrnPhysicalHeight-16,0,14,0,
- "Timing is rough but still, quite impressive ! ");
- x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
- "Clipping slows things down considerably. ");
-
-
- getch();
- x_text_mode();
- }
-
-